<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=request.getContextPath()%>/css/base.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath()%>/css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.pager.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/base.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/admin.js"></script>
<script src="<%=request.getContextPath()%>/js/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/js/swfobject.js" type="text/javascript"></script>
<link href="<%=request.getContextPath()%>/js/uploadify.css" rel="stylesheet" type="text/css" />
<title>列表广告管理</title>
</head>

<BODY class=list><DIV class=bar>列表广告&nbsp;总记录数: ${fn:length(items)}</DIV>
<DIV class=body>
<c:forEach items="${items}" var="item" varStatus="status">
   <DIV  id="${item.goodsType.id}"  class=info style="float:left;line-height:40px;width:80%;padding-left:10px">
      ${item.goodsType.typeName}: 
      <c:forEach items="${item.subTypes}" var="types" varStatus="status">
      <span class="subtypes">${types.typeName}</span>
      </c:forEach>
      <INPUT type="button" class="formButton" value="修改" onclick="openTypeSelect('${item.goodsType.id}','${item.subTypeIds}')" />
    
   </DIV>
 
</c:forEach>
</DIV>

<DIV id="typesSelect" style="Z-INDEX: 103; WIDTH: 600px; DISPLAY: none; HEIGHT: 200px; MARGIN-LEFT: -300px;top:15%"  class=baseDialog >
      <DIV class=dialogWrap></DIV>
      <DIV class=dialogMain>
        <div  class="dialogTitle" style="height:30px;line-height:35px">选择分类</div>
        <DIV class=dialogClose onclick="closeTypeSelect()"></DIV>
        <DIV id="types" style="padding:10px;height:100px">
          
        </DIV>
         <DIV id="types" style="padding:10px">
          <INPUT id=save class=formButton  value="确认" type=button onclick="saveSelectTypes()" >
        </DIV>
     </DIV>
</DIV>
</BODY>

<SCRIPT type=text/javascript><!--
var currenttypeid='';
function openTypeSelect(typeid,subtypeids)
{
 currenttypeid=typeid;
 var url='<%=request.getContextPath()%>/admin/thirdlist.do?id='+typeid;
 $.get(url,{subtypeids:subtypeids}, function(result){	
	  var types=eval('('+result+')');	
	  addhtml(types,subtypeids)
	  $("#typesSelect").show();
	});
}

function addhtml(types,subtypeids)
{
  var html='';
  for(i=0;i<types.length;i++)
  {
    if(types[i].status=='1')
    {
    html=html+'<INPUT value='+types[i].id+'  type=checkbox name=ids checked></TD> <TD>'+types[i].typeName+'</TD> ';   
    }
    else
    {
    html=html+'<INPUT value='+types[i].id+'  type=checkbox name=ids></TD> <TD>'+types[i].typeName+'</TD> ';    
    }
  }
  $("#types").html(html); 
}
function closeTypeSelect()
{
 $("#typesSelect").hide();
}

function saveSelectTypes()
{
 var ids=document.getElementsByName("ids");
  var value='';   
  for (var i=0;i<ids.length;i++ ){ 
   if(ids[i].checked){ //判断复选框是否选中    
     if(value.length>0)
     {
     value=value+','+ids[i].value;
     }else
     {
     value=ids[i].value;
     }
   }   
   }
  var url='<%=request.getContextPath()%>/admin/itemtypesave.do?id='+currenttypeid;
  $.get(url,{typeids:value}, function(result){	
	 // var types=eval('('+result+')');	
	    window.location.reload();
	});

}

</SCRIPT>
</html>